/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-22
 * Time: 17:26
 */
//手写一个死锁代码
public class Test {
    public static void main(String[] args) {
        Object lock1=new Object();
        Object lock2=new Object();
        Thread t1 = new Thread() {
            @Override
            public void run() {
                try{
                    synchronized(lock1){
                        sleep(1000);
                        synchronized(lock2){
                            System.out.println("t1同时拥有2把锁");
                        }
                    }

                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        };
        Thread t2 = new Thread() {
            @Override
            public void run() {
                try{
                    synchronized(lock2){
                        sleep(1000);
                        synchronized(lock1){
                            System.out.println("t2同时拥有2把锁");
                        }
                    }
                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        };
        t1.start();;
        t2.start();
    }
}
